from django.shortcuts import render
from django.shortcuts import HttpResponse
from django.http import JsonResponse
from .utils import TRANSLATION_HTML_TEMPLATE as tht
from .utils import mainProcessOfEnglish

def translate(request):
    data = {}
    if request.method == "POST":
        inputData = request.POST
        if inputData["language"].lower() == "en":
            data["interpretation"] = "EN"
            translationList = mainProcessOfEnglish(inputData['sentences'])
            index = 1
            displayHtml= ''
            for sentenceDict in translationList:
                displayHtml = displayHtml + tht.format(no=str(index),source_sen=sentenceDict['source_sen'],translation_sen=sentenceDict['translation_sen'],vocabulary_sen=sentenceDict['vocabulary_sen'])
                index += 1
            data["vocabulary"]=displayHtml
        elif inputData["language"].lower() == "jp":
            data["interpretation"] = "JP"
    return JsonResponse(data)

def goTranslationPage(request):
    return render(request,'translation.html')
